class slurm::config inherits slurm{
  file{"/etc/slurm":
    ensure   =>  'directory',
    owner    =>  'root',
    group    =>  'root',
  }->

  case $facts['os']['release']['major'] {
  '7': {
    file{"/etc/slurm/cgroup.conf":
      ensure => file,
      owner  => 'slurm',
      group  => 'slurm',
      source => "puppet:///modules/${module_name}/cgroup.conf",
    }
  }
  '9': {
    file{"/etc/slurm/cgroup.conf":
      ensure => file,
      owner  => 'slurm',
      group  => 'slurm',
      source => "puppet:///modules/${module_name}/el9-cgroup.conf",
    }
    file{"/etc/slurm/scrun.lua":
      ensure => file,
      owner  => 'slurm',
      group  => 'slurm',
      source => "puppet:///modules/${module_name}/el9-scrun.lua",
    }
    file{"/etc/slurm/oci.conf":
      ensure => file,
      owner  => 'slurm',
      group  => 'slurm',
      source => "puppet:///modules/${module_name}/el9-oci.conf",
    }

  }
  }

  file{"/var/spool/slurm":
    ensure   =>  'directory',
    owner    =>  'slurm',
    group    =>  'slurm',
  }
  file{"/var/spool/slurm/state":
    ensure   =>  'directory',
    owner    =>  'slurm',
    group    =>  'slurm',
    require  =>  File['/var/spool/slurm'],
  }
  file{"/var/spool/slurm/spool":
    ensure   =>  'directory',
    owner    =>  'slurm',
    group    =>  'slurm',
    require  =>  File['/var/spool/slurm'],
  }
  file{"/var/log/slurm":
    ensure   =>  'directory',
    owner    =>  'slurm',
    group    =>  'slurm',
  }
  logrotate::rule { 'slurmd':
    path         => ['/var/log/slurm/slurmd.log' ],
    dateext      => true,
    rotate       => 9,
    rotate_every => 'week',
    minsize      => '200M',
    postrotate   => '/bin/kill -HUP `cat /var/run/slurmd.pid 2> /dev/null` 2> /dev/null || true',
  }
  logrotate::rule { 'servicelogs':
    ensure => 'absent',
  }
  file{"/usr/local/slurm":
    ensure   =>  'directory',
    owner    =>  'slurm',
    group    =>  'slurm',
  }->
  file { "/usr/local/slurm/prolog_prog":
     ensure   => file,
     owner    => slurm,
     group    => slurm,
     source   => "puppet:///modules/${module_name}/prolog_prog",
     mode     => '0755',
  }->
  file { "/usr/local/slurm/genToken":
     ensure   => file,
     owner    => root,
     group    => root,
     source   => "puppet:///modules/${module_name}/genToken",
     mode     => '0755',
  }
  file { "/etc/munge/munge.key":
     ensure   => file,
     owner    => munge,
     group    => munge,
     source   => "puppet:///modules/${module_name}/munge.key",
     mode     => '0600',
  }
  if $enable_service {
    file { "/etc/slurm/slurm.conf":
       ensure   => file,
       owner    => slurm,
       group    => slurm,
       content  => template("slurm/slurm${facts['os']['release']['major']}.conf.erb"),
       mode     => '0644',
    }
  }
  else {
    file { "/etc/slurm/slurm.conf":
       ensure   => file,
       owner    => slurm,
       group    => slurm,
       content  => template("slurm/slurm${facts['os']['release']['major']}.conf.erb"),
       mode     => '0644',
    }
  }
}
